<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>工作日志 | 个人博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162&#x2F;&#x2F; responseType:&amp;#x27;blob&amp;#x27;&#x2F;&#x2F; arraybuffer	ArrayBuffer对象&#x2F;&#x2F; blob	Blob对象&#x2F;&#x2F; document">
<meta property="og:type" content="article">
<meta property="og:title" content="工作日志">
<meta property="og:url" content="https://gitee.com/wieldy/bailment-blog/2023/07/03/%E5%B7%A5%E4%BD%9C%E6%97%A5%E5%BF%97/index.html">
<meta property="og:site_name" content="个人博客">
<meta property="og:description" content="1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162&#x2F;&#x2F; responseType:&amp;#x27;blob&amp;#x27;&#x2F;&#x2F; arraybuffer	ArrayBuffer对象&#x2F;&#x2F; blob	Blob对象&#x2F;&#x2F; document">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2023-07-03T08:17:38.000Z">
<meta property="article:modified_time" content="2023-07-07T08:21:08.255Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/bailment-blog/atom.xml" title="个人博客" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/bailment-blog/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/bailment-blog/css/style.css">

  
    
<link rel="stylesheet" href="/bailment-blog/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/bailment-blog/" id="logo">个人博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/bailment-blog/">Home</a>
        
          <a class="main-nav-link" href="/bailment-blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/bailment-blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://gitee.com/wieldy/bailment-blog"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-工作日志" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/bailment-blog/2023/07/03/%E5%B7%A5%E4%BD%9C%E6%97%A5%E5%BF%97/" class="article-date">
  <time class="dt-published" datetime="2023-07-03T08:17:38.000Z" itemprop="datePublished">2023-07-03</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      工作日志
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// responseType:&#x27;blob&#x27;</span></span><br><span class="line"><span class="comment">// arraybuffer	ArrayBuffer对象</span></span><br><span class="line"><span class="comment">// blob	Blob对象</span></span><br><span class="line"><span class="comment">// document	Document对象</span></span><br><span class="line"><span class="comment">// json	JS 对象 ， 解析得到的从服务器返回来的JSON字符串</span></span><br><span class="line"><span class="comment">// text	DOMString</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// XMLHttpRequest.responseType 属性是一个枚举类型的属性，返回响应数据的类型。它允许我们手动的设置返回数据的类型。如果我们将它设置为一个空字符串，它将使用默认的&quot;text&quot;类型。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 当将responseType设置为一个特定的类型时，你需要确保服务器所返回的类型和你所设置的返回值类型是兼容的。那么如果两者类型不兼容呢?恭喜你，你会发现服务器返回的数据变成了null，即使服务器返回了数据。还有一个要注意的是，给一个同步请求设置responseType会抛出一个InvalidAccessError 的异常</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 简而言之，　responseType　的作用就是设置ａｊａｘ　数据响应的类型，　你告诉服务器，让服务器返回什么样的数据类型给你</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//数据来源：https://blog.csdn.net/yudldl/article/details/83095523</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> <span class="title function_">download</span>(<span class="params">data: <span class="built_in">any</span></span>) &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">request</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">`/smart/eye/map/legend/details/download?file=<span class="subst">$&#123;data&#125;</span>`</span>,</span><br><span class="line">    <span class="attr">method</span>: <span class="string">&quot;get&quot;</span>,</span><br><span class="line">    <span class="attr">responseType</span>: <span class="string">&quot;blob&quot;</span>,</span><br><span class="line">    <span class="comment">// multipart/form-data转base64 信息来源：https://juejin.cn/post/7251131990438264889</span></span><br><span class="line">    <span class="attr">headers</span>: &#123; <span class="string">&quot;Content-Type&quot;</span>: <span class="string">&quot;multipart/form-data&quot;</span> &#125;</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="title function_">download</span>(nameads.<span class="property">value</span>)</span><br><span class="line">  .<span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// let aBlob = new Blob(array, options);</span></span><br><span class="line">    <span class="keyword">const</span> blob = <span class="keyword">new</span> <span class="title class_">Blob</span>([res], &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&quot;application/pdf&quot;</span>,</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="keyword">const</span> link = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;a&quot;</span>);</span><br><span class="line">    <span class="keyword">const</span> fileName = <span class="string">&quot;202305&quot;</span> + nameads.<span class="property">value</span> + <span class="string">&quot;公司简报.pdf&quot;</span>;</span><br><span class="line">    link.<span class="property">href</span> = <span class="variable language_">window</span>.<span class="property">URL</span>.<span class="title function_">createObjectURL</span>(blob);</span><br><span class="line">    link.<span class="title function_">setAttribute</span>(<span class="string">&quot;download&quot;</span>, fileName);</span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(link);</span><br><span class="line">    link.<span class="title function_">click</span>();</span><br><span class="line">  &#125;)</span><br><span class="line">  .<span class="title function_">catch</span>(<span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> blob = <span class="keyword">new</span> <span class="title class_">Blob</span>([err], &#123;</span><br><span class="line">      <span class="comment">// 如何后端没返回下载文件类型，则需要手动设置：type: &#x27;application/pdf;chartset=UTF-8&#x27; 表示下载文档为pdf，如果是word则设置为msword，excel为excel</span></span><br><span class="line">      <span class="attr">type</span>: <span class="string">&quot;application/pdf&quot;</span>,</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="keyword">const</span> link = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;a&quot;</span>);</span><br><span class="line">    <span class="keyword">const</span> fileName = <span class="string">&quot;202305&quot;</span> + nameads.<span class="property">value</span> + <span class="string">&quot;公司简报.pdf&quot;</span>;</span><br><span class="line">    link.<span class="property">href</span> = <span class="variable language_">window</span>.<span class="property">URL</span>.<span class="title function_">createObjectURL</span>(blob);</span><br><span class="line">    link.<span class="title function_">setAttribute</span>(<span class="string">&quot;download&quot;</span>, fileName);</span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(link);</span><br><span class="line">    link.<span class="title function_">click</span>();</span><br><span class="line">    <span class="comment">// const &#123;msg&#125; = err</span></span><br><span class="line">    <span class="comment">// window.$message.warning(msg||&#x27;请重新刷新数据&#x27;)</span></span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// request.ts中响应拦截器</span></span><br><span class="line">    <span class="comment">// 响应数据为二进制流处理(Excel导出)</span></span><br><span class="line">    <span class="keyword">if</span> (response.<span class="property">data</span> <span class="keyword">instanceof</span> <span class="title class_">ArrayBuffer</span>) &#123;</span><br><span class="line">      <span class="keyword">return</span> response;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 进制流为blob</span></span><br><span class="line">    <span class="keyword">if</span> (response.<span class="property">data</span> <span class="keyword">instanceof</span> <span class="title class_">Blob</span>) &#123;</span><br><span class="line">      <span class="keyword">return</span> response.<span class="property">data</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. .d.ts的顶级声明必须以declare开头</span></span><br><span class="line"><span class="comment">// 2. 以declare声明的变量和模块后，其他地方不需要引入，就可以直接使用了</span></span><br><span class="line"><span class="comment">// 信息来源：https://blog.csdn.net/youhebuke225/article/details/125664535</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">declare</span> <span class="keyword">const</span> <span class="attr">def</span>: <span class="function">(<span class="params">obj: <span class="built_in">object</span>, key: <span class="built_in">string</span> | <span class="built_in">symbol</span>, value: <span class="built_in">any</span></span>) =&gt;</span> <span class="built_in">void</span>;</span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">TypeScript</span>中infer</span><br><span class="line">场景假设：我们有个黑盒类型<span class="title class_">Arr</span>，明确知道<span class="title class_">Arr</span>是一个数组，但确实不知道数组的元素是什么类型，这时候就可以有以下写法：</span><br><span class="line"><span class="comment">// 黑盒类型：</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">Arr</span> = <span class="title class_">Array</span>&lt;<span class="built_in">string</span> | <span class="built_in">number</span>&gt;</span><br><span class="line"><span class="comment">// 获取方法:</span></span><br><span class="line"><span class="keyword">type</span> get&lt;T&gt; = T <span class="keyword">extends</span> <span class="title class_">Array</span>&lt;infer U&gt; ? U : T</span><br><span class="line"><span class="comment">// 获取的结果:</span></span><br><span class="line"><span class="keyword">type</span> B = get&lt;<span class="title class_">Arr</span>&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 另一个例子</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">ThisParameterType</span>&lt;T&gt; = T <span class="keyword">extends</span> (<span class="attr">this</span>: infer U, ...<span class="attr">args</span>: <span class="built_in">never</span>) =&gt; <span class="built_in">any</span> ? U : <span class="built_in">unknown</span>;</span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">服务器渲染 &amp; vue-router</span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> axios, &#123; <span class="keyword">type</span> <span class="title class_">AxiosRequestConfig</span>, <span class="keyword">type</span> <span class="title class_">AxiosResponse</span> &#125; <span class="keyword">from</span> <span class="string">&#x27;axios&#x27;</span>;</span><br></pre></td></tr></table></figure>

<!--
其他了解：
AR、VR、MR、XR的区别
VR：能让人完全沉浸在虚拟环境中
AR：能创建一个叠加在虚拟内容的世界，但不能与真实环境交互
MR：虚拟与现实的混合体，能创造出可以与真实环境交互的虚拟物体
XR：包括三种“现实”（AR/VR/MR）的术语
数据来源：https://baijiahao.baidu.com/s?id=1750979163479963018&wfr=spider&for=pc
微信推出XR-FRAME 实现虚拟现实的交互
-->

<p>虚拟dom的好处？可以跨平台 diff算法<br>编译时：compiler<br>运行时：runtime<br>共享：shared<br>项目管理：Monorepo  分包管理<br>pnpm<br>esbuild</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://gitee.com/wieldy/bailment-blog/2023/07/03/%E5%B7%A5%E4%BD%9C%E6%97%A5%E5%BF%97/" data-id="clowxs0ko0000xqfy6qw8fh0s" data-title="工作日志" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/bailment-blog/2023/06/29/payMent/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">payMent</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/bailment-blog/archives/2023/07/">July 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/bailment-blog/archives/2023/06/">June 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/bailment-blog/archives/2023/04/">April 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/bailment-blog/archives/2023/03/">March 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/bailment-blog/archives/2022/03/">March 2022</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/bailment-blog/2023/07/03/%E5%B7%A5%E4%BD%9C%E6%97%A5%E5%BF%97/">工作日志</a>
          </li>
        
          <li>
            <a href="/bailment-blog/2023/06/29/payMent/">payMent</a>
          </li>
        
          <li>
            <a href="/bailment-blog/2023/06/20/%E7%BD%91%E7%BA%A2%E9%9D%A2%E8%AF%95%E9%A2%98/">原理题</a>
          </li>
        
          <li>
            <a href="/bailment-blog/2023/06/19/%E5%89%8D%E7%AB%AF%E5%A4%A7%E5%B1%8F%E8%87%AA%E9%80%82%E5%BA%94%E6%96%B9%E6%B3%95/">前端大屏自适应方法</a>
          </li>
        
          <li>
            <a href="/bailment-blog/2023/06/17/10%E4%B8%AAJavaScript%E5%B8%B8%E8%A7%81%E9%AB%98%E7%BA%A7%E7%9F%A5%E8%AF%86%E7%82%B9/">10个JavaScript常见高级知识点</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2023 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/bailment-blog/" class="mobile-nav-link">Home</a>
  
    <a href="/bailment-blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/bailment-blog/js/jquery-3.4.1.min.js"></script>



  
<script src="/bailment-blog/fancybox/jquery.fancybox.min.js"></script>




<script src="/bailment-blog/js/script.js"></script>





  </div>
</body>
</html>